package com.ruoyi.project.sms.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.db.sms.domain.SmsGroupon;
import com.ruoyi.db.sms.domain.query.SmsGrouponQueryVo;
import com.ruoyi.project.sms.service.SmsGrouponService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 团购活动Controller
 *
 * @author yfy
 * @date 2020-04-27
 */
@Api(tags="sms管理：团购活动管理")
@RestController
@RequestMapping("/sms/groupon")
public class SmsGrouponController extends BaseController
{
    @Autowired
    private SmsGrouponService smsGrouponService;

    @ApiOperation("查询团购活动列表")
    @PreAuthorize("@ss.hasPermi('sms:groupon:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsGrouponQueryVo smsGrouponQueryVo)
    {
        startPage();
        List<SmsGroupon> list = smsGrouponService.selectSmsGrouponList(smsGrouponQueryVo);
        return getDataTable(list);
    }

    @ApiOperation("导出团购活动列表")
    @Log(title = "团购活动", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('sms:groupon:export')")
    @GetMapping("/export")
    public AjaxResult export(SmsGrouponQueryVo smsGrouponQueryVo)
    {
        List<SmsGroupon> list = smsGrouponService.selectSmsGrouponList(smsGrouponQueryVo);
        ExcelUtil<SmsGroupon> util = new ExcelUtil<SmsGroupon>(SmsGroupon.class);
        return util.exportExcel(list, "groupon");
    }

    @ApiOperation("获取团购活动详细信息")
    @Log(title = "团购活动", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('sms:groupon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smsGrouponService.selectSmsGrouponById(id));
    }

    @ApiOperation("新增团购活动")
    @Log(title = "团购活动", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('sms:groupon:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SmsGroupon smsGroupon)
    {
        return toAjax(smsGrouponService.insertSmsGroupon(smsGroupon));
    }

    @ApiOperation("修改团购活动")
    @Log(title = "团购活动", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('sms:groupon:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SmsGroupon smsGroupon)
    {
        return toAjax(smsGrouponService.updateSmsGroupon(smsGroupon));
    }

    @ApiOperation("删除团购活动")
    @Log(title = "团购活动", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('sms:groupon:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsGrouponService.deleteSmsGrouponByIds(ids));
    }
}
